Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
markdown-table
Advanced tools
The markdown-table npm package is a utility for generating tables in Markdown format. It allows users to create well-formatted Markdown tables from arrays of data, providing options to customize alignment and padding.
Basic Table Creation
This feature allows the creation of a basic Markdown table from an array of arrays. Each sub-array represents a row in the table.
const markdownTable = require('markdown-table');
const table = markdownTable([
['Branch', 'Commit'],
['master', '0123456789abcdef'],
['staging', 'fedcba9876543210']
]);
console.log(table);
Custom Alignment
This feature enables the specification of alignment for each column in the table. 'l' stands for left, 'c' for center, and 'r' for right.
const markdownTable = require('markdown-table');
const table = markdownTable(
[
['Feature', 'Support'],
['Tables', 'Yes'],
['Alignment', 'Yes']
],
{ align: ['l', 'c'] }
);
console.log(table);
The 'table' package also allows for the creation of text-based tables, which can be used in Markdown. It offers more extensive customization options such as border styles and cell content wrapping, making it more versatile than markdown-table for complex table layouts.
Similar to 'table', cli-table3 is designed for creating Unicode-aided tables in the command line interface but can also be used to generate Markdown-compatible tables. It provides additional features like custom header styles and column width control, offering more detailed customization compared to markdown-table.
Generate a markdown (GFM) table.
This is a simple package that takes table data and generates a GitHub flavored markdown (GFM) table.
You can use this package when you want to generate the source code of a GFM table from some data.
This is a simple solution in that it doesn’t handle escapes or HTML or any of
that.
For a complete but heavier solution, build an AST and serialize it with
mdast-util-to-markdown
(with
mdast-util-gfm
).
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
npm install markdown-table
In Deno with esm.sh
:
import {markdownTable} from 'https://esm.sh/markdown-table@3'
In browsers with esm.sh
:
<script type="module">
import {markdownTable} from 'https://esm.sh/markdown-table@3?bundle'
</script>
Typical usage (defaults to align left):
import {markdownTable} from 'markdown-table'
markdownTable([
['Branch', 'Commit'],
['main', '0123456789abcdef'],
['staging', 'fedcba9876543210']
])
Yields:
| Branch | Commit |
| ------- | ---------------- |
| main | 0123456789abcdef |
| staging | fedcba9876543210 |
With align:
markdownTable(
[
['Beep', 'No.', 'Boop'],
['beep', '1024', 'xyz'],
['boop', '3388450', 'tuv'],
['foo', '10106', 'qrstuv'],
['bar', '45', 'lmno']
],
{align: ['l', 'c', 'r']}
)
Yields:
| Beep | No. | Boop |
| :--- | :-----: | -----: |
| beep | 1024 | xyz |
| boop | 3388450 | tuv |
| foo | 10106 | qrstuv |
| bar | 45 | lmno |
This package exports the identifier markdownTable
.
There is no default export.
markdownTable(table[, options])
Generate a markdown table from table data (matrix of strings).
options
Configuration (optional).
options.align
One style for all columns, or styles for their respective columns (string
or
Array<string>
).
Each style is either 'l'
(left), 'r'
(right), or 'c'
(center).
Other values are treated as ''
, which doesn’t place the colon in the alignment
row but does align left.
Only the lowercased first character is used, so Right
is fine.
options.padding
Whether to add a space of padding between delimiters and cells (boolean
,
default: true
).
When true
, there is padding:
| Alpha | B |
| ----- | ----- |
| C | Delta |
When false
, there is no padding:
|Alpha|B |
|-----|-----|
|C |Delta|
options.delimiterStart
Whether to begin each row with the delimiter (boolean
, default: true
).
👉 Note: please don’t use this: it could create fragile structures that aren’t understandable to some markdown parsers.
When true
, there are starting delimiters:
| Alpha | B |
| ----- | ----- |
| C | Delta |
When false
, there are no starting delimiters:
Alpha | B |
----- | ----- |
C | Delta |
options.delimiterEnd
Whether to end each row with the delimiter (boolean
, default: true
).
👉 Note: please don’t use this: it could create fragile structures that aren’t understandable to some markdown parsers.
When true
, there are ending delimiters:
| Alpha | B |
| ----- | ----- |
| C | Delta |
When false
, there are no ending delimiters:
| Alpha | B
| ----- | -----
| C | Delta
options.alignDelimiters
Whether to align the delimiters (boolean
, default: true
).
By default, they are aligned:
| Alpha | B |
| ----- | ----- |
| C | Delta |
Pass false
to make them staggered:
| Alpha | B |
| - | - |
| C | Delta |
options.stringLength
Function to detect the length of table cell content (Function
, default:
s => s.length
).
This is used when aligning the delimiters (|
) between table cells.
Full-width characters and emoji mess up delimiter alignment when viewing the
markdown source.
To fix this, you can pass this function, which receives the cell content and
returns its “visible” size.
Note that what is and isn’t visible depends on where the text is displayed.
Without such a function, the following:
markdownTable([
['Alpha', 'Bravo'],
['中文', 'Charlie'],
['👩❤️👩', 'Delta']
])
Yields:
| Alpha | Bravo |
| - | - |
| 中文 | Charlie |
| 👩❤️👩 | Delta |
With string-width
:
import stringWidth from 'string-width'
markdownTable(
[
['Alpha', 'Bravo'],
['中文', 'Charlie'],
['👩❤️👩', 'Delta']
],
{stringLength: stringWidth}
)
Yields:
| Alpha | Bravo |
| ----- | ------- |
| 中文 | Charlie |
| 👩❤️👩 | Delta |
This package is fully typed with TypeScript.
It exports the additional type Options
.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
This package is safe.
The original idea and basic implementation was inspired by James Halliday’s
text-table
library.
Yes please! See How to Contribute to Open Source.
FAQs
Generate a markdown (GFM) table
The npm package markdown-table receives a total of 3,674,187 weekly downloads. As such, markdown-table popularity was classified as popular.
We found that markdown-table demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.